package com.nhim.cms.admin.client.ioc;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;

import com.nhim.cms.admin.client.AdministrationTree;
import com.nhim.cms.admin.client.AssetsTree;
import com.nhim.cms.admin.client.ContentPagesTree;
import com.nhim.cms.admin.client.Dashboards;
import com.nhim.cms.admin.client.DashboardsTree;
import com.nhim.cms.admin.client.GroupWidget;
import com.nhim.cms.admin.client.LoginWidget;
import com.nhim.cms.admin.client.NhimCMSAdminActivityMapper;
import com.nhim.cms.admin.client.NhimCMSAdminApp;
import com.nhim.cms.admin.client.NhimCMSAdminShell;
import com.nhim.cms.admin.client.NhimCMSAdminTreeMenu;
import com.nhim.cms.admin.client.dashboards.ContentManagement;
import com.nhim.cms.admin.client.eldf.ui.ElementDefinition;
import com.nhim.cms.admin.client.ctype.ui.ContentType;
import com.nhim.cms.admin.client.customwidget.ui.CustomWidgetList;
import com.nhim.cms.admin.client.eldf.ui.ElementDefinitionList;
import com.nhim.cms.admin.client.group.ui.GroupList;
import com.nhim.cms.admin.client.place.NhimCMSAdminPlaceHistoryMapper;
import com.nhim.cms.admin.client.template.ui.TemplateList;
import com.nhim.cms.admin.shared.NhimCMSAdminRequestFactory;

public class NhimCMSAdminFactory {
	
	private final EventBus eventBus = new SimpleEventBus();
	private final NhimCMSAdminRequestFactory requestFactory = GWT.create(NhimCMSAdminRequestFactory.class);
	private final NhimCMSAdminPlaceHistoryMapper historyMapper = GWT.create(NhimCMSAdminPlaceHistoryMapper.class);
	private final PlaceHistoryHandler placeHistoryHandler;
	private final PlaceController placeController = new PlaceController(eventBus); 
	private final Dashboards dashboards = new Dashboards(requestFactory);
	private final AdministrationTree administrationTree = new AdministrationTree(requestFactory);
	private final ContentPagesTree contentPagesTree = new ContentPagesTree(requestFactory);
	private final AssetsTree assetsTree = new AssetsTree(requestFactory);
	private final DashboardsTree dashboardsTree = new DashboardsTree(requestFactory);
	private final LoginWidget loginWidget = new LoginWidget(requestFactory);
	private final GroupWidget groupWidget = new GroupWidget(requestFactory);
	private final ElementDefinitionList elementDefinitionList = new ElementDefinitionList(requestFactory);
	private final ElementDefinition elementDefinition = new ElementDefinition(requestFactory);
	private final CustomWidgetList customWidgetList = new CustomWidgetList(requestFactory);
	private final GroupList groupList = new GroupList(requestFactory);
	private final ContentType contentType = new ContentType(requestFactory);
	private final TemplateList contentTemplateList = new TemplateList(requestFactory);
	private final ContentManagement contentManagement = new ContentManagement(requestFactory);
	private final NhimCMSAdminTreeMenu treeMenu = new NhimCMSAdminTreeMenu(requestFactory);
	private final ActivityMapper activityMapper = new NhimCMSAdminActivityMapper(dashboards
																				,elementDefinitionList
																				,elementDefinition
																				,contentType
																				,customWidgetList
																				,groupList,contentTemplateList,contentManagement);
	private final ActivityManager activityManager = new ActivityManager(
	      activityMapper, eventBus);
	
	 public NhimCMSAdminFactory() {
		    requestFactory.initialize(eventBus);
		    historyMapper.setFactory(this);
		    placeHistoryHandler = new PlaceHistoryHandler(historyMapper);
		  }
	 public NhimCMSAdminApp getNhimCMSAdminApp()
	 {
		return new NhimCMSAdminApp(activityManager
								  ,eventBus
								  ,placeController
								  ,placeHistoryHandler
								  ,dashboardsTree
								  ,administrationTree
								  ,contentPagesTree
								  ,assetsTree
								  ,new NhimCMSAdminShell(loginWidget
										                 ,groupWidget
										                 ,treeMenu
										                 ,dashboards
										                 ,elementDefinitionList
										                 ,elementDefinition
										                 ,contentType
										                 ,customWidgetList
										                 ,groupList,contentTemplateList,contentManagement));
	}

}
